package com.example.mushroom.controller;

import com.example.mushroom.entity.Batch;
import com.example.mushroom.service.BatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/batches")
public class BatchController {

    @Autowired
    private BatchService batchService;

    @PostMapping
    public int insertBatch(@RequestBody Batch batch) {
        return batchService.insertBatch(batch);
    }

    @GetMapping("/{id}")
    public Batch selectBatchById(@PathVariable Integer id) {
        return batchService.selectBatchById(id);
    }

    @GetMapping
    public List<Batch> selectAllBatches() {
        return batchService.selectAllBatches();
    }

    @PutMapping
    public int updateBatch(@RequestBody Batch batch) {
        return batchService.updateBatch(batch);
    }

    @DeleteMapping("/{id}")
    public int deleteBatchById(@PathVariable Integer id) {
        return batchService.deleteBatchById(id);
    }

    @GetMapping("/page")
    public List<Batch> selectBatchesByPage(@RequestParam int offset, @RequestParam int limit) {
        return batchService.selectBatchesByPage(offset, limit);
    }
}